package com.example.module.goods.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.module.goods.form.GetGoodsForm;
import com.example.module.goods.form.GoodsAddForm;
import com.example.module.goods.form.GoodsDeleteByIdForm;
import com.example.module.goods.form.GoodsUpdateForm;
import com.example.module.goods.service.GoodsService;
import com.example.module.goods.vo.GetGoodsVO;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ghy
 * @date 2025/08/12
 * @description 商品控制类
 */
@Validated
@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Resource
    private GoodsService goodsService;

    /*
     * 新增商品
     *
     * @param goodsAddForm
     * @return void
     * */
    @PostMapping("/add")
    @SaCheckLogin
    public void addGoods(@RequestBody GoodsAddForm goodsAddForm) {
        goodsService.addGoods(goodsAddForm);
    }

    /*
     * 删除商品
     *
     * @param goodsDeleteByIdForm
     * @return void
     * */
    @PostMapping("/delete")
    @SaCheckLogin
    public void deleteGoods(@RequestBody GoodsDeleteByIdForm goodsDeleteByIdForm) {
        goodsService.deleteGoodsById(goodsDeleteByIdForm);
    }

    /*
     * 更新商品
     *
     * @param goodsUpdateForm
     * @return void
     * */
    @PostMapping("/update")
    @SaCheckLogin
    public void updateGoods(@RequestBody GoodsUpdateForm goodsUpdateForm) {
        goodsService.updateGoods(goodsUpdateForm);
    }

    /*
     * 获取商品
     *
     * @param getGoodsForm
     * @return List<GetGoodsVO>
     * */
    @PostMapping("/get")
    @SaCheckLogin
    public List<GetGoodsVO> getGoods(@RequestBody GetGoodsForm getGoodsForm) {
        return goodsService.getGoods(getGoodsForm);
    }

    /*
     * 获取商品分页
     *
     * @param getGoodsForm
     * @return Page<GetGoodsVO>
     * */
    @PostMapping("/page")
    @SaCheckLogin
    public Page<GetGoodsVO> getGoodsPage(@RequestBody GetGoodsForm getGoodsForm) {
        return goodsService.getGoodsByPage(getGoodsForm);
    }
}
